<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutGroup}">

<head>
	<meta charset="UTF-8">
	<title>竞赛分数录入</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<!--<el-button type="primary" @click="openRaceApply(null)">添 加</el-button>-->
				<el-table :data="raceApplys" border highlight-current-row style="width: 100%">
					<!-- -->
					<el-table-column prop="applyUserId" label="申请人">
						<template slot-scope="scope">
						{{scope.row.applyUser?.accountName}}
						</template>
					</el-table-column>
					<el-table-column prop="applyCourseId" label="所属竞赛">
						<template slot-scope="scope">
						{{scope.row.applyCourse?.courseTitle}}
						</template>
					</el-table-column>
					<el-table-column prop="applyFile" label="报名文件">
						<template slot-scope="scope">
						<a target="_blank" :href="scope.row.applyFile">查看</a>
						</template>
					</el-table-column>
					<!--<el-table-column prop="applyStatus" label="状态">
						<template slot-scope="scope">
						{{['待提交资料','待审核','审核通过','弃赛'][scope.row.applyStatus]}}
						</template>
					</el-table-column>-->
					<el-table-column prop="applyTime" label="申请时间"></el-table-column>
					<!--<el-table-column prop="applyGuide" label="指导内容"></el-table-column>
					<el-table-column prop="applyGuideTime" label="指导时间"></el-table-column>-->
					<el-table-column prop="applyScore" label="分数"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<!--<el-button @click="openRaceApply(scope.row)" type="text" size="small">修 改</el-button>
							<el-popconfirm title="是否删除？" @confirm="delRaceApply(scope.row.applyId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>-->
							<el-button @click="setApplyScore(scope.row.applyId)" type="text" size="small">设置分数</el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="raceApplyForm.ttitle" :visible.sync="raceApplyForm.visible" width="30%">
			<el-form :model="raceApplyForm" :rules="raceApplyRules" ref="raceApplyForm" label-width="100px">
				<!-- -->
				<el-form-item label="申请人" prop="applyUserId">
					<el-input v-model="raceApplyForm.applyUserId"></el-input>
				</el-form-item>
				<el-form-item label="所属竞赛" prop="applyCourseId">
					<el-input v-model="raceApplyForm.applyCourseId"></el-input>
				</el-form-item>
				<el-form-item label="报名文件" prop="applyFile">
					<el-input v-model="raceApplyForm.applyFile"></el-input>
				</el-form-item>
				<el-form-item label="0报名无效，1待审核，2审核通过，3弃赛" prop="applyStatus">
					<el-input v-model="raceApplyForm.applyStatus"></el-input>
				</el-form-item>
				<el-form-item label="分数" prop="applyScore">
					<el-input v-model="raceApplyForm.applyScore"></el-input>
				</el-form-item>
				<el-form-item label="申请时间" prop="applyTime">
					<el-input v-model="raceApplyForm.applyTime"></el-input>
				</el-form-item>
				<el-form-item label="指导内容" prop="applyGuide">
					<el-input v-model="raceApplyForm.applyGuide"></el-input>
				</el-form-item>
				<el-form-item label="指导时间" prop="applyGuideTime">
					<el-input v-model="raceApplyForm.applyGuideTime"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeRaceApply">取 消</el-button>
				<el-button type="primary" @click="saveRaceApply">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		raceApplys: [],
		selectRaceApply: null,
		raceApplyForm: {
			visible: false,
			ttitle: '新增/修改',
			applyId : '',
			applyUserId : '',
			applyCourseId : '',
			applyFile : '',
			applyStatus : '',
			applyScore : '',
			applyTime : '',
			applyGuide : '',
			applyGuideTime : '',
		},
		raceApplyQuery: {
			userId: 'not',
			status: '2',
			page: '',
			size: '',
		},
		raceApplyRules: {
			applyId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyUserId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyCourseId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyFile: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyStatus: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyScore: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyGuide: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			applyGuideTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getRaceApplys() {
			let that = this
			postRequst('/getApplys', that.raceApplyQuery, true).then(function (resp) {
				that.raceApplys = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectRaceApply = resp.rows[0]
				}
			})
		},
		openRaceApply(row) {
			let that = this
			if (row) {
				that.raceApplyForm.ttitle = '修改'
				that.raceApplyForm.applyId = row.applyId
				that.raceApplyForm.applyUserId = row.applyUserId
				that.raceApplyForm.applyCourseId = row.applyCourseId
				that.raceApplyForm.applyFile = row.applyFile
				that.raceApplyForm.applyStatus = row.applyStatus
				that.raceApplyForm.applyScore = row.applyScore
				that.raceApplyForm.applyTime = row.applyTime
				that.raceApplyForm.applyGuide = row.applyGuide
				that.raceApplyForm.applyGuideTime = row.applyGuideTime
			} else {
				that.raceApplyForm.ttitle = '新增'
				that.raceApplyForm.applyId = ''
				that.raceApplyForm.applyUserId = ''
				that.raceApplyForm.applyCourseId = ''
				that.raceApplyForm.applyFile = ''
				that.raceApplyForm.applyStatus = ''
				that.raceApplyForm.applyScore = ''
				that.raceApplyForm.applyTime = ''
				that.raceApplyForm.applyGuide = ''
				that.raceApplyForm.applyGuideTime = ''
			}
			that.raceApplyForm.visible = true
		},
		closeRaceApply() {
			this.$refs["raceApplyForm"].resetFields();
			this.raceApplyForm.visible = false
		},
		saveRaceApply() {
			let that = this
			this.$refs["raceApplyForm"].validate((valid) => {
				if (valid) {
					postRequst('/admin/saveRaceApply', that.raceApplyForm).then(function (resp) {
						if (resp.status == 0) {
							that.getRaceApplys()
							that.raceApplyForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delRaceApply(applyId) {
			let that = this
			postRequst('/admin/delRaceApply', {applyId: applyId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getRaceApplys()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
		setApplyScore(applyId) {
			let that = this
			this.$prompt('请输入分数', '提示', {
	          confirmButtonText: '确定',
	          cancelButtonText: '取消',
	          inputPattern: /^([0-9]{1,2}$)|(^[0-9]{1,2}\.[0-9]{1,2}$)|100$/,
	          inputErrorMessage: '格式不正确'
	        }).then(({ value }) => {
	          	postRequst('/applyScore', {applyId: applyId,score: value}, true).then(function (resp) {
					if (resp.status == 0) {
						that.getRaceApplys()
						that.$message({message: resp.msg, type: "success"});
					} else {
						that.$message({message: resp.msg, type: "error"});
					}
				})
	        }).catch(() => {});
		},
	}
	function vueCreated() {
		let that = this
		that.getRaceApplys()
	}
</script>

</html>